import numpy as np
import pandas as pd
from bokeh import plotting, io
from src.params import DEFAULTFORMAT as FMT
import src.choropleth as choro
FMT.update({'line_width':1, 'line_color':'black'})
choro.empty_map('state', FMT, output='png')
cmplx = pd.read_csv('data/test/fitness_county_new.csv', dtype={'fipstext':str})
supp = pd.read_csv('data/test/cbp_suppression_2016_EMP.csv', dtype={'GEO.id2':str})
p = choro.choropleth_county(supp, 'GEO.id2', 'fips', 'resid', 'divergent', state_outline='None', output='png')
fmt = {'background_color':'#d1d1d1', ## add background color
'line_width':0.5, 'line_color':'#d3d3d3', ## change county line width and color
'fill_alpha':0.8, ## change opaqueness of color
'cbar_textfmt':"0.00", 'cbar_max':0.25, 'cbar_min':-0.25} ## change colorbar formatting
p = choro.choropleth_county(supp, 'GEO.id2', 'fips', 'resid', 'divergent', state_outline=None, formatting=fmt, output='svg')
fmt = {'st_fill':None, 'line_width':0.5, 'palette':2, 'line_color':'#d3d3d3',
'cbar_textfmt':"0.00", 'cbar_max':0.25, 'cbar_min':-0.25, 'fill_alpha':1,
'simplify':0.028, ## simplify geo shape
'background_color':'darkgray'}
p = choro.choropleth_county(supp, 'GEO.id2', 'fips', 'resid', 'divergent', state_outline='after',
formatting=fmt, output='png')
supp_missing = supp.copy()
random = np.random.randint(1, len(supp), size=round(0.3*len(supp)))
supp_missing.iloc[random, 7] = np.nan
choro.choropleth_county(supp_missing, 'GEO.id2', 'fips', 'resid', 'divergent', state_outline='after', formatting=fmt, output='png')
p = choro.choropleth_county(cmplx, 'fipstext', 'fips', 'f_2016', 'sequential', output='png')
fmt = {'simplify':0.028, ## simplify geojson shape
'ncolors':7, 'palette':2, ## specify color palette and number of color breaks
'wt':1200, 'ht':720, ## dimensions for interactive version (web browser)
'background_color':None, 'line_color':'white', 'line_width':0.2, ## transparent background and soft white lines
'st_fill':'#c8c8c8', 'st_alpha':1, 'st_line_width':1, ## color state to be gray and have thick lines
'cbar_title':'Community Fitness', 'cbar_title_align':'center', ## add color bar title
'cbar_tick_alpha':0, 'cbar_min':0, 'cbar_max':7, 'cbar_fontsize':"8pt", ## change color bar font, remove ticks
}
p = choro.choropleth_county(cmplx, 'fipstext', 'fips', 'f_2016', 'sequential', state_outline='both', ## draw state outline before and after
formatting=fmt)
p = choro.choropleth_county(cmplx, 'fipstext', 'fips', 'f_2016', 'sequential', state_outline='before',
formatting=fmt, output='bokeh')
fmt2 = {'background_color':None, 'st_fill':None, 'st_alpha':0, 'st_line_width':1,
'simplify':0.028, 'st_line_color':'black'}
choro.draw_state(p, fmt2)
io.output_notebook()
plotting.show(p)
# io.output_file('cmplx_main.html')
# io.reset_output()